/**
  * Copyright (c) CSIRO Australia, 2009
  *
  * @author $Author: jia020 $
  * @version $Id: Pdsp.java 643 2009-05-20 00:20:55Z jia020 $
  */
package au.csiro.nt.pdsp.client;

import com.google.gwt.core.client.EntryPoint;
import com.gwtext.client.core.Margins;
import com.gwtext.client.core.RegionPosition;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.TabPanel;
import com.gwtext.client.widgets.Viewport;
import com.gwtext.client.widgets.layout.BorderLayout;
import com.gwtext.client.widgets.layout.BorderLayoutData;
import com.gwtext.client.widgets.layout.FitLayout;
/**
 * The GWT client entry point class.
 * EntryPoint for GWT client.
 * EventManager for GWT client.
 */
public class Pdsp implements EventHandler, EntryPoint {
	private QueryPanel queryPanel;
	private QueryResult queryResult;
	private TabPanel tabPanel;
	private int tabID = 1;
	/**
	 * create Login Panel.
	 * @return Login Panel.
	 */	
	private Panel createLoginPanel() {
		LoginPanel loginPanel = new LoginPanel(this);  
		return loginPanel;
	}
	/**
	 * create Operation Panel.
	 * @return Operation Panel.
	 */		
	private Panel createOperationPanel() {
		Panel panel = new Panel();
		panel.setBorder(false);
		panel.setPaddings(15);
		panel.setLayout(new FitLayout());
		Panel borderPanel = new Panel();
		borderPanel.setLayout(new BorderLayout());

		// add north panel
		Panel northPanel = new HeaderPanel();
		northPanel.setHeight(64);
		borderPanel.add(northPanel, new BorderLayoutData(RegionPosition.NORTH));

		// add south panel
		Panel southPanel = new Panel();
		southPanel.setHtml("<p>CSIRO tail</p>");
		southPanel.setHeight(64);
	//	southPanel.setBodyStyle("background-color:#CDEB8B");
		southPanel.setCollapsible(true);

		BorderLayoutData southData = new BorderLayoutData(RegionPosition.SOUTH);
		southData.setMinSize(100);
		southData.setMaxSize(200);
		southData.setMargins(new Margins(0, 0, 0, 0));
		southData.setSplit(true);
		borderPanel.add(southPanel, southData);

		// add centre panel
		tabPanel = new TabPanel();
		//tabPanel.setActiveTab(0);


		BorderLayoutData centerData = new BorderLayoutData(RegionPosition.CENTER);
		centerData.setSplit(true);
		centerData.setMinSize(175);
		centerData.setMaxSize(400);
		centerData.setMargins(new Margins(0, 0, 0, 0));

		borderPanel.add(tabPanel, centerData);
		// add west panel
		Panel westPanel = new NavigationPanel(this);
		BorderLayoutData westData = new BorderLayoutData(RegionPosition.WEST);
		westData.setSplit(true);
		westData.setMinSize(175);
		westData.setMaxSize(400);
		westData.setMargins(new Margins(0, 0, 0, 0));

		borderPanel.add(westPanel, westData);
		// setup viewport
		panel.add(borderPanel);
		Viewport viewport = new Viewport(panel);
		return panel;		
	}
	/**
	 * override function from EntryPoint
	 */		
	public void onModuleLoad() {
		Panel panelLogin = createLoginPanel();
	}
	/**
	 * override function from EventHandler
	 * Processing all the gui event from all subPanels.
	 */	
	@Override
	public void processEvent(int event,String param) {
		
		switch(event) {
		case PdspConst.EVENT_QUERY_PRIVACYDATA:
			Panel tab = new Panel();
			tab.setTitle("Query Result:");
			tab.setId("QueryResult" + tabID);
			queryResult = new QueryResult(param);
			tab.add(queryResult);
			tab.setAutoScroll(true);		
			tab.setClosable(true);
			tabPanel.add(tab);
			tabPanel.setActiveTab(tab.getId());
			tabID++;
			break;
		case PdspConst.EVENT_SHOW_MYTASKS:
			Panel tab1 = new Panel();
			tab1.setTitle("My tasks:");
			tab1.setId("MyTasks"+tabID);
			TasksPanel myTasks = new TasksPanel(this,param);
			tab1.add(myTasks);
			tab1.setAutoScroll(true);		
			tab1.setClosable(true);
			tabPanel.add(tab1);
			tabPanel.setActiveTab(tab1.getId());
			tabID++;
			break;
		case PdspConst.EVENT_SHOW_MYWORKFLOWS:
			Panel tab2 = new Panel();
			tab2.setTitle("My workflows:");
			tab2.setId("MyWorkflows"+tabID);
			WorkflowsPanel myWorkflows = new WorkflowsPanel(this,param);
			tab2.add(myWorkflows);
			tab2.setAutoScroll(true);		
			tab2.setClosable(true);
			tabPanel.add(tab2);
			tabPanel.setActiveTab(tab2.getId());
			tabID++;
			break;
		case PdspConst.EVENT_SHOW_GOOGLEMAP:
			Panel tab3 = new Panel();
			tab3.setTitle("googleMapPanel:");
			tab3.setId("googleMapPanel"+tabID);
			GoogleMapPanel googleMapPanel = new GoogleMapPanel(param);
			tab3.add(googleMapPanel);
			tab3.setAutoScroll(true);		
			tab3.setClosable(true);
			tabPanel.add(tab3);
			tabPanel.setActiveTab(tab3.getId());
			tabID++;
			break;			
		case PdspConst.EVENT_SHOW_OPERATION:
			createOperationPanel();
			break;	
		case PdspConst.EVENT_SHOW_UNREVIEWEDWORKFLOWS:
			Panel tab4 = new Panel();
			tab4.setTitle("Review workflows:");
			tab4.setId("Review"+tabID);
			WFReviewPanel reviewPanel = new WFReviewPanel(this,param);
			tab4.add(reviewPanel);
			tab4.setAutoScroll(true);		
			tab4.setClosable(true);
			tabPanel.add(tab4);
			tabPanel.setActiveTab(tab4.getId());
			tabID++;			
			break;			
		case PdspConst.EVENT_SHOW_QUERY:
			Panel tab5 = new Panel();
			tab5.setTitle("Query:");
			tab5.setId("Query"+tabID);			
			queryPanel = new QueryPanel(this);
			tab5.add(queryPanel);
			tab5.setAutoScroll(true);
			tab5.setClosable(true);			
			tabPanel.add(tab5);	
			tabPanel.setActiveTab(tab5.getId());
			tabID++;			
			break;				
		case PdspConst.EVENT_SHOW_MESSAGES:
			Panel tab6 = new Panel();
			tab6.setTitle("Pending messages:");
			tab6.setId("Message"+tabID);
			MessagesPanel messagesPanel = new MessagesPanel(param);
			tab6.add(messagesPanel);
			tab6.setAutoScroll(true);
			tab6.setClosable(true);
			tabPanel.add(tab6);
			tabPanel.setActiveTab(tab6.getId());
			tabID++;
			break;
		case PdspConst.EVENT_SHOW_SUBSCRIBE:
			Panel tab7 = new Panel();
			tab7.setTitle("Subscribe wizard:");
			tab7.setId("Subscribe"+tabID);
			SubscribePanel subscribePanel = new SubscribePanel(param);
			tab7.add(subscribePanel);
			tab7.setAutoScroll(true);
			tab7.setClosable(true);
			tabPanel.add(tab7);
			tabPanel.setActiveTab(tab7.getId());
			tabID++;
			break;	
		case PdspConst.EVENT_SHOW_WORKFLOWS:
			Panel tab8 = new Panel();
			tab8.setTitle("Admin workflows:");
			tab8.setId("Admin"+tabID);
			WFAdminPanel adminPanel = new WFAdminPanel(this,param);
			tab8.add(adminPanel);
			tab8.setAutoScroll(true);		
			tab8.setClosable(true);
			tabPanel.add(tab8);
			tabPanel.setActiveTab(tab8.getId());
			tabID++;			
			break;				
			}				
	}
}